package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class BaseDataBindingAdapter<B extends ViewDataBinding,T> extends RecyclerView.Adapter<BaseDataBindingAdapter.DataBindingViewHolder> {

    private B binding;
    private Context context;
    private @LayoutRes int layout;
    private List<T> mData;

    public BaseDataBindingAdapter(Context context, int layout, List<T> mData) {
        this.context = context;
        this.layout = layout;
        this.mData = mData;
    }

    @NonNull
    @Override
    public BaseDataBindingAdapter.DataBindingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewDataBinding viewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(context), layout,parent,false);
        return new DataBindingViewHolder(viewDataBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull BaseDataBindingAdapter.DataBindingViewHolder holder, int position) {

    }

    public abstract void onBindViewHolder();

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class DataBindingViewHolder extends RecyclerView.ViewHolder {

        ViewDataBinding carriageDemandBinding;

        public DataBindingViewHolder(ViewDataBinding  view) {
            super(view.getRoot());
            this.carriageDemandBinding = view;
        }

        public ViewDataBinding  getBindings(){
            return carriageDemandBinding;
        }
    }
}
